<?php

declare(strict_types=1);

namespace Tool\Model;

use think\Model;

/**
 * 模型基类.
 */
abstract class AbstractModel extends Model
{
    public function __construct(array $data = [])
    {
        parent::__construct($data);

        static::setDb(Db::make($this->getDbConfig()));

        $isAutoWriteTimestamp = $this->getAutoWriteTimestamp();

        if (is_null($isAutoWriteTimestamp)) {
            // 自动写入时间戳
            $this->isAutoWriteTimestamp($this->getConfig('auto_timestamp', true));
        }

        $dateFormat = $this->getDateFormat();

        if (is_null($dateFormat)) {
            // 设置时间戳格式
            $this->setDateFormat($this->getConfig('datetime_format', 'Y-m-d H:i:s'));
        }
    }

    abstract protected function getDbConfig(): array;
}
